﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IElementExtensions.cs" company="StyleCop for ReSharper Development Team">
//   Copyright (c) StyleCop for ReSharper Development Team. All rights reserved.
// </copyright>
// <summary>
//   Extension methods for Token types.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace JetBrains.ReSharper.Psi.Tree
{
    #region Using Directives

    using System;

    using JetBrains.ReSharper.Psi.CSharp.Tree;

    #endregion

    /// <summary>
    /// Extension methods for Token types.
    /// </summary>
    public static class IElementExtensions
    {
        #region Public Methods

        /// <summary>
        /// Determines if the <see cref="IElement"/> is a whitespace new line.
        /// </summary>
        /// <param name="element">
        /// The <see cref="ITokenNode"/> value to check.
        /// </param>
        /// <returns>
        /// <c>true</c>if <paramref name="element"/> is a New Line; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/>is <c>null</c>.
        /// </exception>
        public static bool IsNewLine(this IElement element)
        {
            var whitespaceNode = element as IWhitespaceNode;
            return whitespaceNode != null && whitespaceNode.IsNewLine;
        }

        /// <summary>
        /// Determines if the <see cref="IElement"/> is a whitespace.
        /// </summary>
        /// <param name="element">
        /// The <see cref="ITokenNode"/> value to check.
        /// </param>
        /// <returns>
        /// <c>true</c>if <paramref name="element"/> is a whitespace; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/>is <c>null</c>.
        /// </exception>
        public static bool IsWhitespace(this IElement element)
        {
            var whitespaceNode = element as IWhitespaceNode;
            return whitespaceNode != null;
        }

        #endregion
    }
}